home *** CD-ROM | disk | FTP | other *** search
- class continued_fraction
- {
- public:
- continued_fraction( long double number);
-
- void restart();
- //
- // step returns the number of steps actually taken. As soon as 'rest'
- // becomes zero further steps do not change the approximation. This
- // can be because the approximation has become exact, or because it
- // has become exteremely good.
- //
- int step( int numsteps = 1);
- long double step_till_relerror( long double max_relerror);
- long double step_till_error( long double max_error);
-
- friend ostream &operator<<( ostream &os, const continued_fraction &it);
-
- long double get_error() const;
- long double get_relerror() const;
- unsigned long numerator() const;
- unsigned long denumerator() const;
-
- private:
- const long double x;
- long double rest;
- unsigned long p_1;
- unsigned long p_2;
- unsigned long q_1;
- unsigned long q_2;
-
- long double fract;
- long double error;
- long double relerror;
-
- Boolean step_once();
- void compute_deriveds();
- };
-
- inline void continued_fraction::compute_deriveds()
- {
- fract = (long double) p_1 / (long double) q_1;
- error = fabs( x - fract);
- relerror = error / x;
- }
-
- inline long double continued_fraction::get_error() const
- {
- return error;
- }
-
- inline long double continued_fraction::get_relerror() const
- {
- return relerror;
- }
-
- inline unsigned long continued_fraction::numerator() const
- {
- return p_1;
- }
-
- inline unsigned long continued_fraction::denumerator() const
- {
- return q_1;
- }
-